package 力扣._100020_删除数对后的最小数组长度;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class Solution {
    public int minLengthAfterRemovals(List<Integer> nums) {
        //找到最长的恒等段大小，减去其余部分的大小
        Map<Integer, Integer> map = new HashMap<>();
        int max = 0;
        for (Integer num : nums) {
            if (!map.containsKey(num))
                map.put(num, 1);
            else
                map.put(num, map.get(num) + 1);
            max = Math.max(map.get(num), max);
        }
        int rest = nums.size() - max;
        if (max == rest)
            return 0;
        if (max < rest) {
            int last = rest - max;
            return last % 2;
        } else {
            return max - rest;
        }
    }
}
